package net.zwet.clanworks.common.enumerations;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: zwet
 * Date: 14-1-14
 * Time: 13:43
 * To change this template use File | Settings | File Templates.
 */
public enum NodeType {
    FORUM (100, "Forum", "Forum"),
    TOPIC(101, "Topic", "Topic"),
    NEWS (200, "NewsItem", "NewsItem"),
    COMMENT (300, "Comment", "Comment");

    private int code;
    private String label;
    private String description;

    private static Map<Integer, NodeType> codeToNodeTypeMapping;

    private NodeType(int code, String label, String description) {
        this.code = code;
        this.label = label;
        this.description = description;
    }

    public static NodeType getStatus(int i) {
        if (codeToNodeTypeMapping == null) {
            initMapping();
        }
        return codeToNodeTypeMapping.get(i);
    }

    private static void initMapping() {
        codeToNodeTypeMapping = new HashMap<Integer, NodeType>();
        for (NodeType s : values()) {
            codeToNodeTypeMapping.put(s.code, s);
        }
    }

    public int getCode() {
        return code;
    }

    public String getLabel() {
        return label;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("Status");
        sb.append("{code=").append(code);
        sb.append(", label='").append(label).append('\'');
        sb.append(", description='").append(description).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
